<template>
	<view>
		<u-navbar title="发布"></u-navbar>
		
		<!-- <view class="title">标题</view> -->
		<!-- <view class="text">
			<u-input v-model="form.title" placeholder="请输入信息标题"></u-input>
		</view> -->
		<!-- <view class="title">内容</view> -->
		<view class="text">
			<u-input :custom-style="custom" type="textarea" v-model="form.content" placeholder="请输入内容"></u-input>
		</view>
		<view class="part">
			<u-upload :action="action" :file-list="fileList" ref='uUpload'></u-upload>
		</view>
		<view class="titles dis_f_sb_c">
			<view>标题</view>
			<view style="width: 400rpx;">
				<u-input  v-model="form.title" placeholder="请输入标题" input-align="right"></u-input>
			</view>
		</view>
		<view class="titles dis_f_sb_c">
			<view>手机号码</view>
			<view style="width: 400rpx;">
				<u-input  v-model="form.tel" placeholder="请输入手机号码" input-align="right"></u-input>
			</view>
		</view>
		<view class="titles dis_f_sb_c">
			<view>有效期</view>
			<view style="width: 400rpx;">
				<u-picker v-model="show" mode="time" @confirm='time'></u-picker>
				<view @click="show = true">{{times?times:'请选择时间'}}</view>
				<!-- <u-input  v-model="form.tel" placeholder="请输入手机号码" input-align="right"></u-input> -->
			</view>
		</view>
		<view style="padding: 20rpx;margin-top: 40rpx;">
			<u-button type="primary" @click="fabu()">立即发布</u-button>
		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				custom:{
					background:'#eee',
					padding:'20rpx'
				},
				action: 'http://5.abcd88.cn/index/index/uploads',
				fileList: [],
				times:'',
				show:false,
				form:{
					typeid:0,
					title:'',
					content:'',
					tel:'',
					pic:['1213213213213213']
				}
			};
		},
		onLoad(e){
			this.form.typeid = e.typeid 
		},
		methods:{
			time(e){
				console.log(e)
				this.times = e.year+'-'+e.month+'-'+e.day
			},
			fabu(){
				let files = [];
								// 通过filter，筛选出上传进度为100的文件(因为某些上传失败的文件，进度值不为100，这个是可选的操作)
				files = this.$refs.uUpload.lists.filter(val => {
					return val.progress == 100;
				})
				console.log(files)
				if(files != ''){
					this.form.pic = []
					files.forEach((item,index)=>{  
						this.form.pic.push(item.response.id)
					})
				}
				this.form.time = this.times
				this.$.ajax(2, 'post', 'fabuinfo', {
					form:this.form,
					uid:this.$.get_data('uid')
				}, (res) => {
					// console.log(res)
					if (res.code == 1) {
						// this.list = res.list
					
					}
				})
								// 如果您不需要进行太多的处理，直接如下即可
								// files = this.$refs.uUpload.lists;
								console.log(this.form)
				// console.log(this.fileList)
			}
		}
	}
</script>

<style lang="scss">
	.part {
		padding: 20rpx;
		background-color: #fff;
		border-bottom: 1rpx solid #E4E7ED;
	}
	.titles {
		padding: 20rpx;
		background-color: #fff;
		border-bottom: 1rpx solid #E4E7ED;
	}
	.text {
		padding: 20rpx;
		// padding-left: 20rpx;
		background-color: #fff;
		// border-bottom: 1rpx solid #E4E7ED;
	}
	.title{
		padding: 20rpx;
		background-color: #F3F4F6;
		color: #aaa;
		border-bottom: 1rpx solid #E4E7ED;
	}
</style>
